package com.zhu.day.controller;

import com.alibaba.fastjson.JSON;
import com.zhu.day.model.Student;
import com.zhu.day.util.BatchThreadUtil;
import com.zhu.day.util.ExportExcelUtil;
import com.zhu.day.util.ExportExcelWrapper;
import com.zhu.day.util.ThreadExecuter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;

@RestController
@RequestMapping("/excel")
public class ExcelController {

    @RequestMapping("/hello")
    public String hello(){
        return "hello";
    }

    @RequestMapping("/get")
    public void getExcel(HttpServletResponse response){
        // 准备数据
        List<Student> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(new Student(i,"张"+i,"男"));
        }
        String[] columnNames = { "ID", "姓名", " 性别"};
        String fileName = "excel1";
        ExportExcelWrapper<Student> util = new ExportExcelWrapper();
        util.exportExcel(fileName, fileName, columnNames, list, response, ExportExcelUtil.EXCEl_FILE_2007);
    }


  /*  public static void main(String[] args) {
        List<Integer> zrevrang = Arrays.asList(1,2,3,4);
        List rankList = BatchThreadUtil.multiGet(zrevrang, ThreadExecuter.executor, 1000l, tuple -> show(tuple));
        System.out.println(JSON.toJSONString(rankList));
    }*/

//    public static void main(String[] args) {
//        System.out.println(getFirstDay());
//
//    }

    public static void main(String[] args) {

        System.out.println("202108251816384159621175001551393151".length());
        for (int i = 0; i < 30; i++) {
            int m = ThreadLocalRandom.current().nextInt(1,6);
            int m1 = ThreadLocalRandom.current().nextInt(1,6);
            if (m==m1){
                System.out.println(m);
            }
        }
    }
    private static final String FORMAT2 = "yyyy-MM-dd";

    public static String getFirstDay() {
        return new SimpleDateFormat(FORMAT2).format(System.currentTimeMillis());
    }

    public static Integer getDayOfWeek(int offset) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.DAY_OF_YEAR, offset);
        calendar.add(Calendar.DAY_OF_WEEK, -1);
        return  calendar.get(Calendar.DAY_OF_WEEK);
    }

    public static Integer show(Integer zrevrang ){
           if (zrevrang > 2){

               return zrevrang;
           }
           return null;
    }
}
